Skip to main content

Sieve + Cycles


Inclusion-Exclusion

Sieve Formula, or Principle of Inclusion-Exclusion

Let A1,A2,,AnA_1, A_2, \cdots, A_n be finite sets. Then

A1A2An=j=1n(1)j1i1,i2,,ijAi1Ai2Aij,\left|A_1 \cup A_2 \cup \cdots \cup A_n\right|=\sum_{j=1}^n(-1)^{j-1} \sum_{i_1, i_2, \cdots, i_j}\left|A_{i_1} \cap A_{i_2} \cap \cdots \cap A_{i_j}\right|,

where {i1,i2,,ij}\left\{i_1, i_2, \cdots, i_j\right\} ranges over all jj-element subsets of [n][n].

Proof

Notice that an element not in A1A2AnA_1 \cup A_2 \cup \cdots \cup A_n is not counted in any term on the right-hand side. Thus we only have to show that each element of A1A2AnA_1 \cup A_2 \cup \cdots \cup A_n is counted exactly once on the right-hand side. To do that, pick any element xA1A2Anx \in A_1 \cup A_2 \cup \cdots \cup A_n. Let S[n]S \subseteq[n] be the set of indices so that xAix \in A_i if and only if iSi \in S, and let s=Ss=|S|. Note that s1s \geq 1. As xAix \in A_i only if iSi \in S, a tt-fold intersection Ai1Ai2AitA_{i_1} \cap A_{i_2} \cap \cdots \cap A_{i_t} cannot contain xx unless (i1,i2,,it)S\left(i_1, i_2, \cdots, i_t\right) \subseteq S. So when determining the number of times xx is counted by the right-hand side, we only have to consider the intersections involving the AiA_i which are indexed by SS. On the other hand, each of these intersections does contain xx. Therefore, the right-hand side counts xx once for each of these subsets, with alternating signs. So altogether, the right-hand side counts the element xx

s(s2)+(s3)+(1)s1(ss)=1s-\left(\begin{array}{l} s \\ 2 \end{array}\right)+\left(\begin{array}{l} s \\ 3 \end{array}\right)-\cdots+(-1)^{s-1}\left(\begin{array}{l} s \\ s \end{array}\right)=1

times. To see that the left-hand side is indeed 11, subtract 11 from both sides, then multiply both sides by 1-1, to get

1s+(s2)(s3)+(1)s(ss)=0=(11)s,1-s+\left(\begin{array}{l} s \\ 2 \end{array}\right)-\left(\begin{array}{l} s \\ 3 \end{array}\right)-\cdots+(-1)^s\left(\begin{array}{l} s \\ s \end{array}\right)=0=(1-1)^s,

which is true by the Binomial theorem.

Theorem 2

For all positive integers nn and kk, the equality

S(n,k)=1k!i=0k(1)i(ki)(ki)n=i=0k(1)i1i!(ki)!(ki)nS(n, k)=\frac{1}{k !} \sum_{i=0}^k(-1)^i\left(\begin{array}{c} k \\ i \end{array}\right)(k-i)^n=\sum_{i=0}^k(-1)^i \frac{1}{i !(k-i) !}(k-i)^n

holds.

Proof

Instead of finding a formula for S(n,k)S(n, k), we will find a formula for k!S(n,k)k ! \cdot S(n, k). The latter is the number of all surjections from [n][n] to [k][k].

It is clear that the number of all functions from [n][n] to [k][k] is knk^n as any element of the domain can be mapped into one of kk elements. However, not all these functions will be surjections; many will miss one, two, or more elements of [k][k] in their image. We have to enumerate those that do not miss any element of kk. This sounds a little bit similar to the previous problem (there we were also interested in the number of certain objects no part of which had a certain property). It is therefore hopeful that the same approach will work here.

Let i[k]i \in[k] and let AiA_i denote the set of all functions from [n][n] to [k][k] whose image does not contain ii. It is then clear that Ai=(k1)n\left|A_i\right|=(k-1)^n as such functions can map any element of [n][n] into any one of k1k-1 elements. Similarly,

Ai1Ai2Aij=(kj)n,\left|A_{i_1} \cap A_{i_2} \cap \cdots \cap A_{i_j}\right|=(k-j)^n,

for all jkj \leq k. Therefore, the sieve formula yields:

A1A2An=j=1n(1)j1i1,i2,,ijAi1Ai2Aij=i=1k(1)i1(ki)(ki)n.\begin{aligned} \left|A_1 \cup A_2 \cdots \cup A_n\right| & =\sum_{j=1}^n(-1)^{j-1} \sum_{i_1, i_2, \cdots, i_j}\left|A_{i_1} \cap A_{i_2} \cap \cdots \cap A_{i_j}\right| \\ & =\sum_{i=1}^k(-1)^{i-1}\left(\begin{array}{c} k \\ i \end{array}\right)(k-i)^n . \end{aligned}

This is the number of functions from [n][n] to [k][k] whose range is not the entire set [k][k]. So the number of those with range [k][k], in other words, the number of surjections, can be obtained by subtracting this number from that of all functions from [n][n] to [k][k], and our claim follows.

Theorem 3

Let ff and gg be functions that are defined on the subsets of [n][n], and whose range is the set of real numbers. Let us assume that ff and gg are connected by

g(S)=TSf(T).g(S)=\sum_{T \subseteq S} f(T) .

Then

f(S)=TSg(T)(1)ST.f(S)=\sum_{T \subseteq S} g(T)(-1)^{|S-T|} .

Proof

If we express g(T)g(T) by values of ff on the right-hand side, we see that for all USU \subseteq S, the value f(U)f(U) will appear once for each set TT satisfying UTSU \subseteq T \subseteq S. Each such appearance of f(U)f(U) will be counted with a sign given by (1)ST(-1)^{|S-T|}. The number of such subsets TT for which ST=i|S-T|=i is equal to (SUi)\left(\begin{array}{c}|S-U| \\ i\end{array}\right), since TT is determined by the elements of SS that are not in TT, and TT contains UU.

Therefore, f(U)f(U) will appear on the right-hand side exactly i=0SU(1)i(SUi)=(11)SU\sum_{i=0}^{|S-U|}(-1)^i\left(\begin{array}{c}|S-U| \\ i\end{array}\right)=(1-1)^{|S-U|} times. This number is always zero, except when SU=0|S-U|=0, that is, when S=US=U. So the only term on the right-hand side that does not cancel out will be f(S)f(S), and the claim is proved.


Cycles in Permutations

Lemma 1

Let p:[n][n]p:[n] \rightarrow[n] be a permutation, and let x[n]x \in[n]. Then there exists a positive integer 1in1 \leq i \leq n so that pi(x)=xp^i(x)=x.

Proof

Consider the entries p(x),p2(x),,pn(x)p(x), p^2(x), \cdots, p^n(x). If none of them is equal to xx, then the Pigeon-hole Principle implies that there are two of them that are equal, say pj(x)=pk(x)p^j(x)=p^k(x), with j<kj<k. Then, applying p1p^{-1} to both sides of this equation, we get pj1(x)=pk1(x)p^{j-1}(x)=p^{k-1}(x). Repeating this step, we get pj2(x)=pk2(x)p^{j-2}(x)=p^{k-2}(x), and repeating this step j3j-3 more times, we get p(x)=pkj+1(x)p(x)=p^{k-j+1}(x).

Definition

Let p:[n][n]p:[n] \rightarrow[n] be a permutation. Let x[n]x \in[n], and let ii be the smallest positive integer so that pi(x)=xp^i(x)=x. Then we say that the entries x,p(x),p2(x),,pi1(x)x, p(x), p^2(x), \cdots, p^{i-1}(x) form an ii-cycle in pp.

Corollary

All permutations can be decomposed into the disjoint unions of their cycles.

Proof

Lemma above shows that each entry is a member of a cycle. By the definition of cycles, distinct cycles are disjoint.

Definition

The number of nn-permutations with kk cycles is called a signless Stirling number of the first kind, and is denoted by c(n,k)c(n, k). The number s(n,k)=(1)nkc(n,k)s(n, k)=(-1)^{n-k} c(n, k) is called a Stirling number of the first kind.

Theorem 1

Let nn and kk be positive integers satisfying nkn \geq k. Then

c(n,k)=c(n1,k1)+(n1)c(n1,k).c(n, k)=c(n-1, k-1)+(n-1) c(n-1, k) .

Proof

We show that the right-hand side counts all nn-permutations with kk cycles, just as the left-hand side. In such a permutation, there are two possibilities for the position of the entry nn.

  1. The entry nn can form a cycle by itself, and then the remaining n1n-1 entries have to form k1k-1 cycles. This can happen in c(n1,k1)c(n-1, k-1) ways, so the first member of the right-hand side enumerates these permutations.
  2. If the entry nn does not form a cycle by itself, then the remaining n1n-1 entries must form kk cycles, and then the entry nn has to be inserted somehow into one of these cycles. The kk cycles can be formed in c(n1,k)c(n-1, k) ways, then the entry nn can be inserted in any of these cycles, after each element. This multiplies the number of possibilities by n1n-1, and explains the second term of the right-hand side.

Lemma 2

Let nn be a fixed positive integer. Then

k=0nc(n,k)xk=x(x+1)(x+n1)\sum_{k=0}^n c(n, k) x^k=x(x+1) \cdots(x+n-1)

Proof

We prove that the coefficients of xkx^k on the right-hand side also satisfy the recurrence relation (Theorem 1) that is satisfied by the signless Stirling numbers of the first kind. Let Gn(x)=x(x+1)(x+n1)=k=0nan,kxkG_n(x)=x(x+1) \cdots(x+n-1)=\sum_{k=0}^n a_{n, k} x^k. Then

Gn(x)=(x+n1)Gn1(x)=(x+n1)k=0n1an1,kxk=k=1nan1,k1xk+(n1)k=0n1an1,kxk.\begin{aligned} G_n(x) & =(x+n-1) G_{n-1}(x)=(x+n-1) \sum_{k=0}^{n-1} a_{n-1, k} x^k \\ & =\sum_{k=1}^n a_{n-1, k-1} x^k+(n-1) \sum_{k=0}^{n-1} a_{n-1, k} x^k . \end{aligned}

We have just proved that

k=0nan,kxk=k=1nan1,k1xk+(n1)k=0n1an1,kxk.\sum_{k=0}^n a_{n, k} x^k=\sum_{k=1}^n a_{n-1, k-1} x^k+(n-1) \sum_{k=0}^{n-1} a_{n-1, k} x^k .

In other words, we proved that two polynomials were identical. The only way that can happen is when the coefficients of the corresponding terms agree in the two polynomials. That is, the equality

an,k=an1,k1+(n1)an1,ka_{n, k}=a_{n-1, k-1}+(n-1) a_{n-1, k}

must hold for all positive integers nn and kk such that nkn \geq k. Therefore, the numbers an,ka_{n, k} and c(n,k)c(n, k) do satisfy the same recurrence relation. As their initial terms trivially agree, that is, c(0,0)=a0,0=1,c(n,0)=an,0=0c(0,0)=a_{0,0}=1, c(n, 0)=a_{n, 0}=0 if n>0n>0, this implies that c(n,k)=an,kc(n, k)=a_{n, k}.